主题
启动软件自更新 - SoftUpdateStart
函数简介
用户主动触发自更新:内部调用更新状态接口获取包信息,下载并校验后释放内嵌 ola_updater.exe 并启动。
仅查询是否有更新请使用 GetSoftUpdateStatus,本接口负责执行更新。
返回数据格式:
json
{
"Code": 1,
"Message": "updater started, please exit host process to continue",
"HasUpdate": true,
"NeedExit": true,
"PackagePath": "C:\\App\\.ola_update\\cache\\1.2.0\\app.zip",
"UpdaterPath": "C:\\App\\.ola_update\\cache\\ola_updater.exe",
"UpdaterPid": 4321,
"VersionNumber": "1.2.0",
"PackageType": "zip",
"LogDir": "C:\\App\\.ola_update\\logs"
}| 字段名 | 类型 | 说明 |
|---|---|---|
| Code | 整数 | 1 成功;0 失败。 |
| Message | 字符串 | 结果说明或错误信息。 |
| HasUpdate | 布尔 | 是否存在可更新版本。无更新时 Code 仍可为 1。 |
| NeedExit | 布尔 | 为 true 时请退出宿主,以便 Updater 覆盖/安装。 |
| PackagePath | 字符串 | 已下载安装包本地路径。 |
| UpdaterPath | 字符串 | 已释放的 Updater 路径。 |
| UpdaterPid | 整数 | Updater 进程 ID。 |
| VersionNumber | 字符串 | 目标版本号。 |
| PackageType | 字符串 | zip、rar 或 exe(.msi 按 exe 安装器处理)。 |
| LogDir | 字符串 | 更新日志目录(.ola_update\logs)。 |
接口名称
SoftUpdateStartDLL调用
long SoftUpdateStart(string userCode, string softCode, string softVersion, string dealerCode,
string installRoot, string silentArgs, string launchPath, int waitPid);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| userCode | 字符串 | 用户码。 |
| softCode | 字符串 | 软件码。 |
| softVersion | 字符串 | 当前软件版本。 |
| dealerCode | 字符串 | 经销商码。 |
| installRoot | 字符串 | 安装根目录(zip/rar 覆盖目标;日志/缓存也写在此)。必填。 |
| silentArgs | 字符串 | exe/msi 静默参数,原样传给安装包(如 Inno /VERYSILENT /NORESTART、NSIS /S);zip/rar 可传空。 |
| launchPath | 字符串 | 更新完成后可选拉起的主程序路径,可空。 |
| waitPid | 整数 | 等待退出的进程 PID;传 0 表示等待当前进程。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
"C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
if (result.Code == 1 && result.NeedExit) {
// 退出宿主,让 Updater 继续
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
@"C:\App", "/S", @"C:\App\MyApp.exe", 0);
// result.NeedExit == true 时请退出宿主python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
json_result = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
r"C:\App", "/S", r"C:\App\MyApp.exe", 0)
# Python SDK 返回 JSON 字符串,需自行解析java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateStartReturn;
OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
"C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
// result.NeedExit == true 时请退出宿主go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
result := ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
`C:\App`, "/S", `C:\App\MyApp.exe`, 0)
// result.NeedExit == true 时请退出宿主rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let result = ola.soft_update_start(
"userCode", "softCode", "1.0.0", "dealerCode",
r"C:\App", "/S", r"C:\App\MyApp.exe", 0);
// result.need_exit == true 时请退出宿主cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)text
.局部变量 ola, OLAPlug
.局部变量 result, OlaSoftUpdateStartReturn
ola.创建 ()
result = ola.SoftUpdateStart(“userCode”, “softCode”, “1.0.0”, “dealerCode”, “C:\App”, “/S”, “C:\App\MyApp.exe”, 0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
"C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
// Aardio SDK 返回 JSON 字符串,需自行解析text
变量 ola <类型 = OLAPlugServer>
变量 result <类型 = OlaSoftUpdateStartReturn>
ola = 新建 OLAPlugServer
result = ola.SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode", "C:\App", "/S", "C:\App\MyApp.exe", 0)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateStartReturn result = ola.SoftUpdateStart(
"userCode", "softCode", "1.0.0", "dealerCode",
"C:\\App", "/S", "C:\\App\\MyApp.exe", 0);原生 DLL 调用
cpp
long ptr = SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode",
"C:\\App", "/S", "C:\\App\\MyApp.exe", 0);
if (ptr != 0) {
char buffer[4096] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateStart(string userCode, string softCode, string softVersion,
string dealerCode, string installRoot, string silentArgs, string launchPath, int waitPid);
long ptr = SoftUpdateStart("userCode", "softCode", "1.0.0", "dealerCode",
@"C:\App", "/S", @"C:\App\MyApp.exe", 0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateStart(
b"userCode", b"softCode", b"1.0.0", b"dealerCode",
b"C:\\App", b"/S", b"C:\\App\\MyApp.exe", 0)
if ptr:
buf = create_string_buffer(4096)
ola.GetStringFromPtr(ptr, buf, 4096)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 调用方式 | 返回值 | 说明 |
|---|---|---|
| SDK | OlaSoftUpdateStartReturn | 结构化返回对象;Code == 1 表示启动流程成功 |
| 原生 DLL | 非 0 | 成功,返回 JSON 字符串指针 |
| 原生 DLL | 0 | 失败 |
注意事项
| 项目 | 说明 |
|---|---|
| 退出宿主 | 返回 NeedExit=true 后必须退出占用安装目录的进程,否则 zip/rar 覆盖可能失败并回滚。 |
| 下载进度 | 下载阶段可用 SoftUpdateGetProgress。 |
| 结果查询 | 结束后用 SoftUpdateGetLastStatus:无日志/成功 → Code=1;失败 → Code=0。 |
| 失败摘要 | SoftUpdateGetLastError。 |
| 模块说明 | 软件自更新模块总览(含 SoftUpdateDemo 详细流程)。 |
| 释放内存 | 原生返回指针需 FreeStringPtr。 |
